package com.heima.wemedia.controller;

import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping
@Api(value = "素材管理")
public class WmMaterialController {

   @Autowired
    WmMaterialService wmMaterialService;
   @PostMapping("/api/v1/material/upload_picture")
   @ApiOperation("上传图片")
    public ResponseResult uploadPic(MultipartFile multipartFile){
       return wmMaterialService.uploadPic(multipartFile);
   }
   @PostMapping("/api/v1/material/list")
    public PageResponseResult materialList(@RequestBody WmMaterialDTO dto ){
      return wmMaterialService.materialList(dto);
   }

    @GetMapping("/api/v1/material/del_picture/{id}")
    public ResponseResult deletePictureById(@PathVariable("id") Integer id){
        return wmMaterialService.deletePictureById(id);
    }
    @ApiOperation("取消收藏素材")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
    @ApiOperation("收藏素材")
    @GetMapping("/collect/{id}")
    public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
    }
}
